package com.github.linmt.dbdoc4j.utils;

/**
 * User: Linmt
 * Date: 2022/12/4
 * Time: 20:45
 * Description: 命名工具类
 */
public class NameUtils {

    public static void main(String[] args) {
        System.out.println(toCamelCase("table_name"));
    }

    /**
     * 下划线转驼峰
     *
     * @param s
     * @return
     */
    public static String toCamelCase(String s) {
        if (s == null) {
            return null;
        }
        s = s.toLowerCase();
        StringBuilder sb = new StringBuilder(s.length());
        boolean upperCase = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);

            if (c == '_') {
                upperCase = true;
            } else if (upperCase) {
                sb.append(Character.toUpperCase(c));
                upperCase = false;
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
